//
//  ViewController.m
//  SDCache
//
//  Created by yoxnet on 15/11/23.
//  Copyright © 2015年 yoxnet. All rights reserved.
//

#import "ViewController.h"
#import "SDCache.h"
#import "Model.h"

#import <objc/runtime.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    
 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
   

    //NSLibraryDirectory  Users/pantao/Library/Developer/CoreSimulator/Devices/9E090C44-3817-4492-A4AC-C7C8AFF5A3FA/data/Containers/Data/Application/CF5495DC-015D-4979-8138-2684A9AE489D/Library
    //NSDocumentDirectory  Users/pantao/Library/Developer/CoreSimulator/Devices/9E090C44-3817-4492-A4AC-C7C8AFF5A3FA/data/Containers/Data/Application/A1181374-76FA-4A9E-884F-8822BC20016E/Documents
    
    ///NSCachesDirectory  Users/pantao/Library/Developer/CoreSimulator/Devices/9E090C44-3817-4492-A4AC-C7C8AFF5A3FA/data/Containers/Data/Application/0BD65FCB-661A-4695-B742-78168A9E4D97/Library/Caches
    
    for (NSString * path in paths) {
        
        NSLog(@"path %@",path);
        
    }
    [self test];

    
    
}

-(void)test
{
    SDCache * sd = [SDCache shareSDCacheManager];
    
    NSObject * obj;
    
    NSArray * arr = @[@"这是ffdadaaaa",@34];
    
    NSDictionary * dict = @{@"arr":arr,@"哈哈":@4567};
    
    NSString * str = @"this is a string.";
    
    Byte buffer[256] = {0x54,0x38,0x67,0x59,0x45};
    
    
    
    
    NSData * data = [NSData dataWithBytes:buffer length:5];
    
    NSLog(@"%@",data);
    
    
    //    [sd storeObject:arr forKey:@"test" options:SDCacheTypeDisk];
#if 1
    [sd storeObjectSDCache:arr forkey:@"arr"];
    
    
    [sd storeObjectSDCache:dict forkey:@"dict"];
    
    [sd storeObjectSDCache:str forkey:@"str"];
    
    [sd storeObjectSDCache:data forkey:@"data"];
    
    
    Model * md = [[Model alloc]init];
    
    md.name = @"name";
    md.num = @345;
    md.i=99;
    
    
    [sd storeCustomObjectSDCache:md forkey:@"object"];
    
//    NSString * content = [sd objectInCacheForKey:@"test"];
#endif
    
   md = [sd customObjectInCacheForKey:@"object"];
    
    NSLog(@"%@",md.name);
    
    arr = [sd objectInCacheForKey:@"arr"];
    
    obj = [sd objectInCacheForKey:@"dict"];
    
    obj = [sd objectInCacheForKey:@"str"];
    
    obj = [sd objectInCacheForKey:@"data" isData:YES];
    
    //    NSLog(@"fileCount %ld,totalSize %ld",[sd getSDCacheDiskCount],[sd getSDCacheSize]);
    
    //    [sd calculateSDCacheSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
    //
    //
    //        NSLog(@"block fileCount %ld,totalSize %ld",fileCount,totalSize);
    //
    //    }];
    //    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
